#include "stack.h"

stack_t * stackcreat(void)
{
    stack_t * stk = (stack_t*)malloc(sizeof(stack_t));
    if(stk == NULL)
    {
        printf("stk创建失败!\n");
        return NULL;
    }

    memset(stk,0,sizeof(stack_t));
    stk->top = -1;

    return stk;
}

void stackshow(stack_t * stk)//遍历
 {
    if(stk == NULL)
    {
        printf("空链表!\n");
        return ;
    }
    for(int i=0;i<=stk->top;i++)
    {
        printf("-%d",stk->data[i]);
    }
    putchar(10);
 }
    
int  stackfull(stack_t*stk)
{
    return stk->top + 1 == size ? 0:1;
}
void stackpush(stack_t * stk,datatype data)//
{
    if(stackfull==NULL)
    {
        printf("栈表满了!\n");
        return ;
    }
    stk->data[++stk->top] = data;
        
}

int stackempty(stack_t *stk)//判空
{
    return stk->top == -1 ? 0: 1; 
}

datatype stackpop(stack_t *stk)//出栈
{
    if(stackempty == 0)
    {
        printf("栈为空!\n");
        return (datatype) -1;
    }
    return stk->data[stk->top--];
}